<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="司机id" prop="driverId">
      <el-input v-model="dataForm.driverId" placeholder="司机id"></el-input>
    </el-form-item>
    <el-form-item label="交易内容" prop="content">
      <el-input v-model="dataForm.content" placeholder="交易内容"></el-input>
    </el-form-item>
    <el-form-item label="交易类型：1-奖励 2-补贴 3-提现" prop="tradeType">
      <el-input v-model="dataForm.tradeType" placeholder="交易类型：1-奖励 2-补贴 3-提现"></el-input>
    </el-form-item>
    <el-form-item label="金额" prop="amount">
      <el-input v-model="dataForm.amount" placeholder="金额"></el-input>
    </el-form-item>
    <el-form-item label="交易编号" prop="tradeNo">
      <el-input v-model="dataForm.tradeNo" placeholder="交易编号"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="updateTime">
      
<el-input v-model="dataForm.updateTime" placeholder="修改時間"></el-input>
    </el-form-item>
    <el-form-item label="是否刪除" prop="isDeleted">      <el-input v-model="dataForm.isDeleted" placeholder="是否刪除"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          driverId: '',
          content: '',
          tradeType: '',
          amount: '',
          tradeNo: '',
          createTime: '',
          updateTime: '',
          isDeleted: ''
        },
        dataRule: {
          driverId: [
            { required: true, message: '司机id不能为空', trigger: 'blur' }
          ],
          content: [
            { required: true, message: '交易内容不能为空', trigger: 'blur' }
          ],
          tradeType: [
            { required: true, message: '交易类型：1-奖励 2-补贴 3-提现不能为空', trigger: 'blur' }
          ],
          amount: [
            { required: true, message: '金额不能为空', trigger: 'blur' }
          ],
          tradeNo: [
            { required: true, message: '交易编号不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/driver/driveraccountdetail/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 200) {
                this.dataForm.driverId = data.driverAccountDetail.driverId
                this.dataForm.content = data.driverAccountDetail.content
                this.dataForm.tradeType = data.driverAccountDetail.tradeType
                this.dataForm.amount = data.driverAccountDetail.amount
                this.dataForm.tradeNo = data.driverAccountDetail.tradeNo
                this.dataForm.createTime = data.driverAccountDetail.createTime
                this.dataForm.updateTime = data.driverAccountDetail.updateTime
                this.dataForm.isDeleted = data.driverAccountDetail.isDeleted
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/driver/driveraccountdetail/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'driverId': this.dataForm.driverId,
                'content': this.dataForm.content,
                'tradeType': this.dataForm.tradeType,
                'amount': this.dataForm.amount,
                'tradeNo': this.dataForm.tradeNo,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'isDeleted': this.dataForm.isDeleted
              })
            }).then(({data}) => {
              if (data && data.code === 200) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
